/*
 * 文 件    名:  AllCatelogModel.java
 * 创建日期:  2012-12-16下午2:43:54
 * 版          权:  Epro Technologies Co., Ltd. Copyright 2011-2012,  All rights reserved
 * 作          者:  yw66009
 */
package com.weipu.common.facade.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.weipu.common.constants.ServerConstant;

/** 
 * @Description 所有目录model
 * @version [版本号, 2012-12-16]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author yw66009
 */
public class AllCatelogModel extends CatelogModel
{
    /** 
     * 
     * @Fields serialVersionUID :  
     *
     */
    private static final long serialVersionUID = 7454978384534042573L;
    
    /** 
     * @Fields itemCList : 子CatelogModel
     */
    private List<CatelogModel> itemCList = new ArrayList<CatelogModel>();
    
    public List<CatelogModel> getItemCList()
    {
        return itemCList;
    }
    
    public void setItemCList(List<CatelogModel> itemCList)
    {
        this.itemCList = itemCList;
    }
    
    /**
     * 所有的目录转换成list
     * @param json格式的CatelogModel对象  = {ID:3345,ShortName:'computer',Icon:'http://'}
     * @return CatelogModel对象
     */
    public AllCatelogModel json2allCategories(JSONObject json)
    {
        if (null == json)
        {
            return null;
        }
        AllCatelogModel model = new AllCatelogModel();
        
        model.setBrowseID(json.optInt(ServerConstant.Catelog.CONSTANT_ID));
        if (json.optString(ServerConstant.Catelog.CONSTANT_NEWHEADLINE) != JSONObject.NULL
            && !json.isNull(ServerConstant.Catelog.CONSTANT_NEWHEADLINE))
        {
            model.setShortName(json.optString(ServerConstant.Catelog.CONSTANT_NEWHEADLINE));
        }
        JSONArray jsonArray = json.optJSONArray(ServerConstant.Catelog.CONSTANT_CHILDS);
        if (jsonArray.length() != 0)
        {
            
            for (int i = 0; i < jsonArray.length(); i++)
            {
                itemCList.add(CatelogModel.json2ChildCategories(jsonArray.optJSONObject(i)));
            }
            
            model.setItemCList(itemCList);
            
        }
        
        return model;
    }
}
